package test.session;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class JudgeLoginInfoServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();
        String userNameStr = req.getParameter("username");
        String passwordStr = req.getParameter("password");
        String verifyStr = req.getParameter("verify");
        String verfyImageStr =  (String)req.getSession().getAttribute("verify_code");
        if (userNameStr.equals("shuoGG")) {
            if (passwordStr.equals("123123")) {
                if(verfyImageStr.toLowerCase().equals(verifyStr.toLowerCase()))
                {
                session.setAttribute("result", "OK");
                resp.sendRedirect(req.getContextPath()+"/ResultOK.jsp");// /ServletTest2/ResultOK.jsp
                }
                else{//验证码错误
                    session.setAttribute("result", "verifyerror");
                    resp.sendRedirect(req.getContextPath()+"/login.jsp");
                }
            } else {//密码或用户错误
                session.setAttribute("result", "error");
                resp.sendRedirect(req.getContextPath()+"/login.jsp");
            }
        } else {//密码或用户错误
            session.setAttribute("result", "error");
            resp.sendRedirect(req.getContextPath()+"/login.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

}
